#include "testsummator.h"
#include <QSignalSpy>
#include <QtTest/QtTest>

TestSummator::TestSummator():QObject(NULL), m_sum(new Summator(this)) {}

TestSummator::TestSummator(QObject * parent):QObject(parent), m_sum(new Summator(this))
{
    m_sum->setA(0);
    m_sum->setB(0);
}

void TestSummator::test_setA()
{
    m_sum->setA(10);
    m_sum->setB(10);
    QCOMPARE(m_sum->sum(), 20);
}

void TestSummator::test_setB()
{
    m_sum->setA(0);
    m_sum->setB(5);
    QCOMPARE(m_sum->sum(), 5);
}

void TestSummator::test_sum()
{
    m_sum->setA(0);
    m_sum->setB(5);
    QCOMPARE(m_sum->sum(), 5);
}

void TestSummator::test_valueChanged()
{
    QSignalSpy spy(m_sum, SIGNAL(valueChanged()));
    m_sum->setA(2);
    m_sum->setB(3);
    QCOMPARE(spy.count(), 2);
    m_sum->setB(3);
    QCOMPARE(spy.count(), 2);
}
